﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TS_XY_Train_Repaire.UserCon.Report
{
    public partial class us_Report_Field_ManaForm : DevExpress.XtraEditors.XtraForm
    {
        public us_Report_Field_ManaForm()
        {
            InitializeComponent();
        }
        public string _LoadType="";
        public string _LoadID="";
        private void btclose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btok_Click(object sender, EventArgs e)
        {
            if (f_fieldname.Text.Trim ()!= "" && f_name.Text.Trim() != "" && f_rull.Text.Trim() != "")
            {
                string f_resulttype = "1";
                string f_atype = "0";
                if (rb0.Checked)
                {
                    f_resulttype = "0";
                }
                if (rb1.Checked)
                {
                    f_resulttype = "1";
                }
                if (rb2.Checked)
                {
                    f_resulttype = "2";
                }
                if (rb_Pub.Checked)
                {
                    f_atype = "0";
                }
                if (rb_Auth.Checked)
                {
                    f_atype = "1";
                }
                if (_LoadType == "Edit")
                {
                    TS_Win_Class.MySqlCom("update TS_S_T_P_Report_Field set f_name='" + f_name.Text.Trim() + "',f_fieldname='" + f_fieldname.Text.Trim() + "',f_resulttype='" + f_resulttype + "',f_type=" + f_type.SelectedIndex + ",f_atype=" + f_atype + ",f_rull=" + f_rull.Text.Trim() + ",f_workerid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time=getdate() where f_id=" + _LoadID);
                }
                else if (_LoadType == "Add")
                {
                    TS_Win_Class.MySqlCom(@"insert into TS_S_T_P_Report_Field(f_rmid,f_name,f_fieldname,f_resulttype,f_type,f_atype,f_rull,f_workerid)
                        values(" + _LoadID + ",'" + f_name.Text.Trim() + "','" + f_fieldname.Text.Trim() + "'," + f_resulttype + "," + f_type.SelectedIndex + "," + f_atype + "," + f_rull.Text.Trim() + "," + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ")");
                }
                else
                {
                    TS_Win_Class.MySqlCom("update TS_S_T_P_Report_Field set f_del=1,f_workerid="+TS_Win_Locomotive_MainForm.pUserInfoMain.GuId+",f_time=getdate() where f_id=" + _LoadID);
                }
                this.DialogResult = DialogResult.OK;
            }
            else {
                MessageBox.Show("数据未填写完整！");
            }
        }

        private void us_Report_Field_ManaForm_Load(object sender, EventArgs e)
        {
            f_type.SelectedIndex = 0;
            if (_LoadType!="Add")
            {
                DataTable dt = TS_Win_Class.GetFilledDataTable("select * from TS_S_T_P_Report_Field where f_del=0 and f_id="+ _LoadID);
                f_name.Text = dt.Rows[0]["f_name"].ToString();
                f_fieldname.Text = dt.Rows[0]["f_fieldname"].ToString();
                switch (dt.Rows[0]["f_resulttype"].ToString())
                {
                    case "0":
                        rb0.Checked = true;
                        break;
                    case "1":
                        rb1.Checked = true;
                        break;
                    case "2":
                        rb2.Checked = true;
                        break;
                    default:
                        break;
                }
                switch (dt.Rows[0]["f_atype"].ToString())
                {
                    case "0":
                        rb_Pub.Checked = true;
                        break;
                    case "1":
                        rb_Auth.Checked = true;
                        break;
                    default:
                        break;
                }
                f_type.SelectedIndex = Convert.ToInt32(dt.Rows[0]["f_type"]);
                f_rull.Text = dt.Rows[0]["f_rull"].ToString();
            }
        }

    }
}